﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static Dictionary<int, Student> student = new Dictionary<int, Student>();
        static void Main(string[] args)
        {
            //Student s1 = new Student(1,"a",18);
            //Student s2 = new Student(2, "b", 18);
            //Student s3 = new Student(3, "c", 18);

            //student.Add(s1.No,s1);
            //student.Add(s2.No,s2);
            //student.Add(s3.No,s3);

            //Welcome();

            //User user = new User();
            //user.account = "qwe";
            //user.username = "aaa";
            //user.password = "12323";
            //user.userMsg();

            Student1 stu1 = new Student1(1,"qqq","男",-1,"软件");
            stu1.stu();

            book book = new book(1,"qqq",-3,"aaa","vvv");
            book.book1();

            Console.ReadKey();
        }
        public static void Welcome()
        {
            Console.WriteLine("请选择：1、添加学生信息。2、删除学生信息 3、查询学生信息。");
            int key = int.Parse(Console.ReadLine());
            switch (key)
            {
                case 1:
                    addstudent();
                    Welcome();
                    break;
                case 2:
                    deletestudent();
                    Welcome();
                    break;
                case 3:
                    checkstudent();
                    break;
                default:
                    Console.WriteLine("输错了");
                    break;
            }
        }
        public static void deletestudent()
        {
            Student adds = new Student();
            Console.WriteLine("请输入你要删除的学生的学号：");
            int No = int.Parse(Console.ReadLine());
            if (student.ContainsKey(No))
            {
                student.Remove(No);
                Console.WriteLine("删除成功！");
            }
            else
            {
                Console.WriteLine("没有这个学生！");
            }
        }
        public static void checkstudent()
        {
            Console.WriteLine("查询学生信息功能中有：1、查询所有（按学号排序）2、查询所有（按姓名排序），2、查询所有（按年龄排序）4、按学号查询（查没有，则打印查无此学生）5、退出");
            int key = int.Parse(Console.ReadLine());
            switch (key)
            {
                case 1:
                    List<Student> no = student.Values.ToList();
                    no.Sort(new numsort());
                    PrintList(no);
                    Welcome();
                    break;
                case 2:
                    List<Student> name = student.Values.ToList();
                    name.Sort(new namesort());
                    PrintList(name);
                    Welcome();
                    break;
                case 3:
                    List<Student> age = student.Values.ToList();
                    age.Sort(new agesort());
                    PrintList(age);
                    Welcome();
                    break;
                case 4:
                    Console.WriteLine("输入你要查询的学生的学号：");
                    int a = int.Parse(Console.ReadLine());
                    if (student.ContainsKey(a))
                    {
                        Console.WriteLine(student[a]);
                        Welcome();
                    }
                    else
                    {
                        Console.WriteLine("没有这个学生");
                        Welcome();
                    }
                    break;
                case 5:
                    Console.WriteLine("退出");
                    break;
                default:
                    break;
            }


        }
        private static void PrintList(List<Student> list)
        {
            foreach (Student item in list)
            {
                Console.WriteLine(item);
            }
        }
        public static void addstudent()
        {
            Student adds = new Student();

            Console.WriteLine("请输入学号：");
            adds.No = int.Parse(Console.ReadLine());

            if (student.ContainsKey(adds.No))
            {
                Console.WriteLine("已存在，别重复添加！");
            }
            else
            {
                student[adds.No] = adds;
            }
            Console.WriteLine("请输入姓名：");
            adds.Name = Console.ReadLine();
            Console.WriteLine("请输入年龄：");
            adds.Age =int.Parse(Console.ReadLine());

            Welcome();
        }


    }
}
